package cn.tedu.charging.cost.dao.repository.impl;

import cn.tedu.charging.cost.dao.repository.CostCacheRepository;
import cn.tedu.charging.cost.pojo.po.CostRulePO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import java.util.Collections;
import java.util.List;

/**
 * @Author: Miyako
 * @Date: 2024-10-27-19:53
 * @Description:
 */
@Repository
public class CostCacheRepositoryImpl implements CostCacheRepository {


    private static final  String COST_KEY = "COST_RULE_KEY";

    @Autowired
    private RedisTemplate<String, List<CostRulePO>> redisTemplate;

    @Override
    public List<CostRulePO> getCostRuleByStationId(Integer stationId) {
        ValueOperations<String, List<CostRulePO>> stringListValueOperations = redisTemplate.opsForValue();
        String costRuleKey = COST_KEY + stationId;
        List<CostRulePO> costRulePOList = stringListValueOperations.get(costRuleKey);
        return costRulePOList;
    }

    @Override
    public void saveCostRules(Integer stationId,List<CostRulePO> costRules) {
        ValueOperations<String, List<CostRulePO>> stringListValueOperations = redisTemplate.opsForValue();
        String costRuleKey = COST_KEY + stationId;
        stringListValueOperations.set(costRuleKey,costRules);

    }
}
